<template>
	<view>
		<view class="px-3">
			<view class="flex py33 border-bottom align-center" @click="addUser">
				<text class="iconfont" :class="iconStyle" style="font-size: 48rpx;"></text>
				<view class="" style="margin-left: 30rpx;" :class="fontStyle">
					添加紧急联系人
				</view>
			</view>
			<template v-if="contactList.length>0">
				<view class="flex py33 border-bottom align-center text-primary" v-for="(item,index) in contactList"
					:key="index" @click="editUser(item)">
					<view style="margin-left: 68rpx;">{{item.name}}</view>
					<view style="margin-left: 12rpx;" v-if="item.mobile">{{formatPhone(item.mobile)}}</view>
				</view>

			</template>

			<!-- 底部提示 -->
			<view class="" style="margin-top: 405rpx;">
				<text class="font-md text-secondary">添加紧急联系人(最多三位)</text>
				<view class="mt-5 text-secondary notice">
					为了能在上门护理时，更好保障您的安全，请添加紧急
					联系人。添加完成，护理行程以<text class="main-text-color">短信形式</text>
					自动发送至紧急联系人.
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		selectAllUrgencyLinkman
	} from '../../../apis/security/index.js'
	export default {
		data() {
			return {
				contactList: [],
			}
		},
		components: {},
		onShow() {
			this.init()
		},
		computed: {
			iconStyle() {
				// console.log(this.contactList,'suzhu ');
				if (!this.contactList || this.contactList.length < 3) {
					return 'icon-tianjia'
				} else {
					return 'icon-a-tianjiawu'
				}
			},
			fontStyle() {
				if (!this.contactList || this.contactList.length < 3) {
					return 'text-primary'
				} else {
					return 'text-muted'
				}
			},

		},
		onLoad(option) {

		},
		methods: {
			async init() {
				let res = await selectAllUrgencyLinkman()
				if (res.success) {
					this.contactList = res.object
				}
				console.log(res, 'lianxirrrrrr.');
			},
			// 添加紧急联系人
			addUser() {
				if (this.contactList && this.contactList.length == 3) {
					console.log(this.contactList.length)
					// plus.nativeUI.toast("最多添加三位紧急联系人");
					plus.nativeUI.toast('最多添加三位紧急联系人')
					// uni.showToast({
					// 	title:'最多添加三位紧急联系人',
					// 	icon:'none'
					// })
				} else {
					uni.navigateTo({
						url: '../edit/edit'
					})
				}
			},
			editUser(item) {
				uni.navigateTo({
					url: '../edit/edit?item=' + encodeURIComponent(JSON.stringify(item))
				})
			},
			formatPhone(tel) {
				let res = tel.substr(0, 3) + '****' + tel.substr(7)
				return res
			}
		}
	}
</script>
<style scoped lang="less">
	.notice {
		text-indent: 1em;
	}
</style>